package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TbHomeRecommendsProduct;
import com.ruoyi.system.domain.vo.CommonData;
import com.ruoyi.system.domain.vo.ProductQuantity;
import com.ruoyi.system.domain.vo.RecommenCommodities;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbAppletHomepageInfo;
import com.ruoyi.system.service.ITbAppletHomepageInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 小程序首页信息管理 Controller
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/homepage")
public class TbAppletHomepageInfoController extends BaseController
{
    @Autowired
    private ITbAppletHomepageInfoService tbAppletHomepageInfoService;


    /**
     * 配置套餐商品
     */
//    @RequiresPermissions("system:package:add")
//    @Log(title = "首页推荐商品配置", businessType = BusinessType.INSERT)
    @RequestMapping("/configureRecommenCommoditiesCustom")
    public AjaxResult configureRecommenCommodities(@RequestBody RecommenCommodities recommenCommodities)
    {

        int homepageId = recommenCommodities.getHomepageId();

        List<Long> selectedProducts = recommenCommodities.getSelectedProducts();

        return toAjax(tbAppletHomepageInfoService.configureRecommenCommodities(homepageId,selectedProducts));
    }




    /**
     * 查询已配置推荐商品列表
     */
//    @RequiresPermissions("system:homepage:list")
    @GetMapping("/selectTbHomeRecommendsProductList/{homepageId}")
    public TableDataInfo selectTbHomeRecommendsProductList(@PathVariable("homepageId") Long homepageId)
    {
        List<TbHomeRecommendsProduct> list = tbAppletHomepageInfoService.selectTbHomeRecommendsProductList( homepageId);

        return getDataTable(list);
    }


    /**
     * 查询小程序首页信息管理 列表
     */
    @RequiresPermissions("system:homepage:list")
    @GetMapping("/list")
    public TableDataInfo list(TbAppletHomepageInfo tbAppletHomepageInfo)
    {
        startPage();
        List<TbAppletHomepageInfo> list = tbAppletHomepageInfoService.selectTbAppletHomepageInfoList(tbAppletHomepageInfo);
        return getDataTable(list);
    }

    /**
     * 导出小程序首页信息管理 列表
     */
    @RequiresPermissions("system:homepage:export")
    @Log(title = "小程序首页信息管理 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbAppletHomepageInfo tbAppletHomepageInfo)
    {
        List<TbAppletHomepageInfo> list = tbAppletHomepageInfoService.selectTbAppletHomepageInfoList(tbAppletHomepageInfo);
        ExcelUtil<TbAppletHomepageInfo> util = new ExcelUtil<TbAppletHomepageInfo>(TbAppletHomepageInfo.class);
        util.exportExcel(response, list, "小程序首页信息管理 数据");
    }

    /**
     * 获取小程序首页信息管理 详细信息
     */
    @RequiresPermissions("system:homepage:query")
    @GetMapping(value = "/{homepageId}")
    public AjaxResult getInfo(@PathVariable("homepageId") Long homepageId)
    {


        return success(tbAppletHomepageInfoService.selectTbAppletHomepageInfoByHomepageId(homepageId));
    }

    /**
     * 新增小程序首页信息管理 
     */
    @RequiresPermissions("system:homepage:add")
    @Log(title = "小程序首页信息管理 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAppletHomepageInfo tbAppletHomepageInfo)
    {
        return toAjax(tbAppletHomepageInfoService.insertTbAppletHomepageInfo(tbAppletHomepageInfo));
    }

    /**
     * 修改小程序首页信息管理 
     */
    @RequiresPermissions("system:homepage:edit")
    @Log(title = "小程序首页信息管理 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAppletHomepageInfo tbAppletHomepageInfo)
    {
        return toAjax(tbAppletHomepageInfoService.updateTbAppletHomepageInfo(tbAppletHomepageInfo));
    }

    /**
     * 删除小程序首页信息管理 
     */
    @RequiresPermissions("system:homepage:remove")
    @Log(title = "小程序首页信息管理 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{homepageIds}")
    public AjaxResult remove(@PathVariable Long[] homepageIds)
    {
        return toAjax(tbAppletHomepageInfoService.deleteTbAppletHomepageInfoByHomepageIds(homepageIds));
    }
}
